﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SelfManagement.Utility.Helper
{
    public static class PasswordGenerator
    {
        public static string GeneratePassword()
        {
            string password = "";
            Random randomizer = new Random();

            List<Range> ranges = new List<Range>()
            {
                new Range() { Lowerbound = 97, Upperbound = 123 }, //lowercase
                new Range() { Lowerbound = 65, Upperbound = 91 }, //uppercase
                new Range() { Lowerbound = 48, Upperbound = 58 } //numbers
            };

            for (int x = 0; x <= 8; x++)
            {
                int rangeIndex = randomizer.Next(0, 3);
                var range = ranges[rangeIndex];

                password += Convert.ToChar(randomizer.Next(range.Lowerbound, range.Upperbound));
            }

            return password;
        }

        private struct Range
        {
            public int Lowerbound;
            public int Upperbound;
        }
    }
}
